package cn.uai.activiti8.controller;

import cn.uai.activiti8.service.PortalService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @desc 门户控制器，统一对外提供服务
 * @author uai
 * @since 2025/8/7 10:26
 * @version 1.0
 */
@RestController
@RequestMapping("/portal")
public class PortalController {

    @Resource
    private PortalService portalService;

    /**
     * 启动流程
     * @param body
     * @return
     */
    @PutMapping("/approval/start")
    public String start(@RequestBody String body) {
        return portalService.start(body);
    }

    /**
     * 委派
     * @param body
     * @return
     */
    @PutMapping("/approval/delegate")
    public String delegate(@RequestBody String body) {
        return portalService.delegate(body);
    }

    /**
     * 完成任务
     * @param body
     * @return
     */
    @PutMapping("/approval/complete")
    public String complete(@RequestBody String body) {
        return portalService.complete(body);
    }

    /**
     * 完成委派任务
     * @param body
     * @return
     */
    @PutMapping("/approval/completeDelegation")
    public String completeDelegation(@RequestBody String body) {
        return portalService.completeDelegation(body);
    }

    /**
     * 手动部署流程（备用）
     * 备注：按照 Activiti 的规范，把 bpmn20.xml 文件放在 /resource/processes 下，启动 SpringBoot 时会自动解析该文件并部署流程
     * @param body
     * @return
     */
    @PostMapping("/deploy/process")
    public String deploy(@RequestBody String body) {
        return portalService.deploy(body);
    }

    /**
     * 用 deployId 查询已部署的流程定义
     * @param deployId 部署id
     * @return
     */
    @GetMapping("/deploy/processDefinitionQuery/{deployId}")
    public String deployProcessDefinitionQuery(@PathVariable("deployId") String deployId) {
        return portalService.processDefinitionQuery(deployId);
    }

    /**
     * 用 processDefinitionName 查询已部署的有哪些流程定义
     * @param name 流程定义名称
     * @return
     */
    @GetMapping("/deploy/processDefinitionDeployQuery/{name}")
    public String processDefinitionDeployQuery(@PathVariable("name") String name) {
        return portalService.processDefinitionDeployQuery(name);
    }
}
